package org.ithasu.tools.data.impl;

import org.ithasu.tools.data.Entity;
import org.ithasu.tools.data.EntityProvider;

public final class IterableEntityProvider<E extends Entity> implements EntityProvider<E> {

	private final Iterable<E> entities;

	public IterableEntityProvider(Iterable<E> entities) {
		this.entities = entities;
	}

	@Override
	public E getEntityById(long index) {
		for (E e : entities) {
			if (e.getId() == index) {
				return e;
			}
		}
		return null;
	}

}
